/******************************************************************************

  Copyright (C), 2012-2016, ZHANGYA

 ******************************************************************************
  File Name     : main.h
  Version       : Initial Draft
  Author        : zhangya
  Created       : 2024/4/17
  Last Modified :
  Description   : main.h
  Function List :
  History       :
  1.Date        : 2024/4/17
    Author      : zhangya
    Modification: Created file

******************************************************************************/

#ifndef _MAIN_H_
#define _MAIN_H_

#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>

#include "at32f403_clock.h"

#include "configs.h"
#include "debug.h"
#include "delay.h"

#ifdef __cplusplus
extern "C" {
#endif

#define KEY_PWR_Pin					GPIO_PINS_15
#define KEY_PWR_GPIO_Port			GPIOA

#define PWR_OUT_Pin					GPIO_PINS_4
#define PWR_OUT_GPIO_Port			GPIOA

#define KEY_UP_Pin					GPIO_PINS_4
#define KEY_UP_GPIO_Port			GPIOB

#define KEY_DOWN_Pin				GPIO_PINS_3
#define KEY_DOWN_GPIO_Port			GPIOB

#define KEY_MENU_Pin				GPIO_PINS_0
#define KEY_MENU_GPIO_Port			GPIOD

#define PWR_LED_Pin					GPIO_PINS_3
#define PWR_LED_GPIO_Port			GPIOA

#define BEEP_CTL_Pin				GPIO_PINS_12
#define BEEP_CTL_GPIO_Port			GPIOA

#define FAN_ERROR3_Pin				GPIO_PINS_5
#define FAN_ERROR3_GPIO_Port		GPIOA

#define FAN_ERROR2_Pin				GPIO_PINS_6
#define FAN_ERROR2_GPIO_Port		GPIOA

#define FAN_ERROR1_Pin				GPIO_PINS_7
#define FAN_ERROR1_GPIO_Port		GPIOA

#define LCD_BRIGH_Pin				GPIO_PINS_0
#define LCD_BRIGH_GPIO_Port			GPIOA

#define LCD_FMARK_Pin				GPIO_PINS_11
#define LCD_FMARK_GPIO_Port			GPIOA

#define LCD_RD_Pin					GPIO_PINS_0
#define LCD_RD_GPIO_Port			GPIOB

#define LCD_WR_Pin					GPIO_PINS_1
#define LCD_WR_GPIO_Port			GPIOB

#define LCD_RS_Pin					GPIO_PINS_5
#define LCD_RS_GPIO_Port			GPIOB

#define LCD_CS_Pin					GPIO_PINS_6
#define LCD_CS_GPIO_Port			GPIOB

#define LCD_RST_Pin					GPIO_PINS_7
#define LCD_RST_GPIO_Port			GPIOB

#define LCD_DB10_Pin				GPIO_PINS_15
#define LCD_DB10_GPIO_Port			GPIOB

#define LCD_DB11_Pin				GPIO_PINS_14
#define LCD_DB11_GPIO_Port			GPIOB

#define LCD_DB12_Pin				GPIO_PINS_13
#define LCD_DB12_GPIO_Port			GPIOB

#define LCD_DB13_Pin				GPIO_PINS_12
#define LCD_DB13_GPIO_Port			GPIOB

#define LCD_DB14_Pin				GPIO_PINS_11
#define LCD_DB14_GPIO_Port			GPIOB

#define LCD_DB15_Pin				GPIO_PINS_10
#define LCD_DB15_GPIO_Port			GPIOB

#define LCD_DB16_Pin				GPIO_PINS_9
#define LCD_DB16_GPIO_Port			GPIOB

#define LCD_DB17_Pin				GPIO_PINS_8
#define LCD_DB17_GPIO_Port			GPIOB


#define MAX(_x,_y)                  (((_x)>(_y))?(_x):(_y))
#define MIN(_x,_y)                  (((_x)<(_y))?(_x):(_y))

extern const char _make_data[];
extern const char _make_time[];

inline void set_bit_32(unsigned int * value, unsigned char bit)
{
	*value |= (1U << bit);
}

inline unsigned int get_bit_32(unsigned int value, unsigned char bit)
{
	return (value >> bit) & 1U;
}

inline void set_bit_16(unsigned short * value, unsigned char bit)
{
	*value |= (1U << bit);
}

inline unsigned int get_bit_16(unsigned short value, unsigned char bit)
{
	return (value >> bit) & 1U;
}

inline void set_bit_8(unsigned char * value, unsigned char bit)
{
	*value |= (1U << bit);
}

inline unsigned int get_bit_8(unsigned char value, unsigned char bit)
{
	return (value >> bit) & 1U;
}

#ifdef __cplusplus
}
#endif

#endif //#ifndef _MAIN_H_

